﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using interfaces = umbraco.interfaces;
using cms = umbraco.cms;

namespace Elliance.Umbraco.XPathEvaluator
{
    public class XPathEvaluatorTree : cms.presentation.Trees.BaseTree
    {
        public XPathEvaluatorTree(string application) : base(application) 
        { 
        }

        protected override void CreateRootNode(ref cms.presentation.Trees.XmlTreeNode rootNode)
        {
            string iconPath = "../../plugins/xpath-evaluator/images/xpath-evaluator-icon.png";
            rootNode.Icon = iconPath;
            rootNode.OpenIcon = iconPath;
            rootNode.NodeType = "init" + TreeAlias;
            rootNode.NodeID = "init";
            rootNode.Text = "XPath Evaluator";
            rootNode.Action = "javascript:openXPathEvaluator();";
        }

        public override void RenderJS(ref System.Text.StringBuilder javascript)
        {
            javascript.Append(@"
function openXPathEvaluator() {
    parent.right.document.location.href = 'plugins/xpath-evaluator/xpath-evaluator.aspx';
}");

        }

        public override void Render(ref cms.presentation.Trees.XmlTree tree)
        {
        }

        protected override void CreateAllowedActions(ref List<interfaces.IAction> actions)
        {
            actions.Clear();
        }

        protected override void CreateRootNodeActions(ref List<interfaces.IAction> actions)
        {
            actions.Clear();
        }
    }
}
